﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace He.Web.user
{
    public partial class center : System.Web.UI.Page
    {
        public Model.member Member = new Model.member();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Request.IsAuthenticated)
            {
                FormsAuthentication.RedirectToLoginPage();
                return;
            }

            BLL.member mgr = new BLL.member();
            string username = User.Identity.Name;
            if (mgr.Exists(username))
            {
                this.Member = mgr.GetModel(username);
            }
            else
            {
                Response.Redirect("~/error.aspx?s=用户不存在");
            }
        }

        public string GetText(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return "尚未填写";
            }
            return text;
        }

        ///// <summary>
        ///// 获取客户端IP地址
        ///// </summary>
        ///// <returns></returns>
        //public string GetClientIP()
        //{
        //    string userHostAddress = HttpContext.Current.Request.UserHostAddress;

        //    if (string.IsNullOrEmpty(userHostAddress))
        //    {
        //        userHostAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
        //    }

        //    //最后判断获取是否成功，并检查IP地址的格式（检查其格式非常重要）
        //    if (!string.IsNullOrEmpty(userHostAddress) && IsIP(userHostAddress))
        //    {
        //        return userHostAddress;
        //    }
        //    return "未知IP";// "127.0.0.1";
        //}

        ///// <summary>
        ///// 检查IP地址格式
        ///// </summary>
        ///// <param name="ip"></param>
        ///// <returns></returns>
        //public bool IsIP(string ip)
        //{
        //    return System.Text.RegularExpressions.Regex.IsMatch(ip, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$");
        //}
    }
}